<?php
include('top.php');
require_once('pasmy/dbwaarden.php');
if(empty($_SESSION['taal'])) {
	session_destroy();
		Header( "HTTP/1.1 301 Moved Permanently" );
		 
		Header( "Location: login.php" ); 
}
$mysql_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysql_id);
if(isset($_POST["jaar"])) {
$waardb = "vnzvrn" . $_POST["jaartal"];

$teller = 0;
$sql = "select client from $waardb";
$res = mysql_query($sql, $mysql_id);
//mysql_real_escape_string($res);
while ($row = mysql_fetch_row($res)) {
	$client[$teller] = addslashes(trim($row[0]));
	$teller++;
	
}
 
$eerste = count($client);
if($eerste == "0") {echo "<br /><br /><br /><h2><div style='text-align: center'>Aucun &eacute;l&eacute;ment &agrave; afficher</div></h2><br>";exit;}

foreach($client as $key => $value) {
	//echo "sleutel = $key en waarde  = $value<br>";
	//echo "waarde = $value<br>";
	$value = strtolower($value);
	//echo "alles lowercase = $value<br>";
	$value = ucwords($value);
	//echo "eerste hoofdletter = $value<br>";
	$client[$key] = $value;

}
$client1 = array_unique($client);

unset($client);

$tweede = count($client1);

$teller = 0;
foreach($client1 as $key => $waarde) {
	$client[$teller] = $waarde;
	$teller++;
	
	}

$teller = 0;
unset($client1);

foreach($client as $naam) {
	$sql = "select prijs,gasoil from $waardb where client = '$naam'";
	$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$total = $total + $row[0] + $row[1];
	}
	$client1[$naam] = $total;
	 
	$total = 0;
	mysql_free_result($res);
}
unset($client);

arsort($client1);

?>
<table border="1" align="center" width="50%">
<tr><td colspan="2" class="delsaux"><?php echo $totk[$taal];?></td></tr>
<tr>
<td class="delsaux2" width="40%"><strong><?php echo $klant[$taal];?></strong></td><td class="delsaux2" width="10%"><strong><?php echo $pprijs[$taal];?></strong></td>
</tr>
<?php
$total = 0;
foreach ($client1 as $key => $value) {
	$total = $total + $value;
	echo "<tr><td><strong>" . stripslashes($key). "</strong></td><td><strong><div style='text-align: center'>" . number_format($value,2,',', '.') . " &euro;</div></strong></td></tr>";
	}
?>
<tr><td>&nbsp;</td><td class="delsaux2"><?php echo number_format($total,2,',', '.');?></td></tr>
</table>
<?php
}
else {
$jaartal = date("Y");
?>	
<form action="clienttotal.php" method="post">
<table align="center" width="40%" border="1">
<tr><td colspan="2" class="delsaux2"><?php echo $totk[$taal];?></td></tr>
<tr><td width="30%"><strong><?php echo $totjaar[$taal];?></strong></td><td width="10%"><input type="text" name="jaartal"  value="<?php echo $jaartal;?>" /></td></tr>
<tr><td colspan="2"><div style="text-align: center"><br /><input type="submit" name="jaar" value="<?php echo $tonen[$taal];?>"/></div></td></tr>
</table>

</form>
<?php	
}
include('footer.php');
?>